package com.rao.gmall.product.controller;

import com.rao.gmall.common.result.Result;
import com.rao.gmall.common.result.ResultCodeEnum;
import com.rao.gmall.model.product.BaseCategory1;
import com.rao.gmall.model.product.BaseCategory2;
import com.rao.gmall.model.product.BaseCategory3;
import com.rao.gmall.model.vo.IndexCategoryVo;
import com.rao.gmall.product.service.CategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author nzmxfan
 * @create 2021-07-31-16:55
 */
@RestController
@RequestMapping("/admin/product")
public class CategoryAdminController {

    @Resource
    CategoryService categoryService;

    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){

        List<BaseCategory1> baseCategory1List = categoryService.getCategory1List();
        if (baseCategory1List.size() > 0){
            return Result.ok(baseCategory1List);
        } else {
            return Result.build(null, ResultCodeEnum.SECKILL_FAIL);
        }
    }

    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable Long category1Id){

        List<BaseCategory2> baseCategory2List = categoryService.getCategory2List(category1Id);
        if (baseCategory2List.size() > 0){
            return Result.ok(baseCategory2List);
        } else {
            return Result.build(null, ResultCodeEnum.SECKILL_FAIL);
        }
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable Long category2Id){

        List<BaseCategory3> baseCategory3List = categoryService.getCategory3List(category2Id);
        if (baseCategory3List.size() > 0){
            return Result.ok(baseCategory3List);
        } else {
            return Result.build(null, ResultCodeEnum.SECKILL_FAIL);
        }
    }

    @GetMapping("/getAllCategorys")
    public List<IndexCategoryVo> getAllCategorysForIndexHtml(){

        return categoryService.getAllCategorysForIndexHtml();
    }
}
